home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / toadmod1.zip / TOADMOD1.ASM < prev    next >
Assembly Source File  |  1989-04-18  |  4KB  |  153 lines

  1. ;mode1.ASM - program to set COM1-COM4 port to 38400 baud.
  2.  
  3. ;This version corrects a bug in the original 19200 program which
  4. ;prevented it from setting COM2-COM4.  It only worked on COM1.
  5. ;Corrections made by Keith Petersen, W8SDZ, January 21, 1989.
  6.  
  7. ;v1.1
  8. ; - Stupid error .. swapping ax/cx instead of ax/dx .. dumb!
  9. ;
  10. ;Toad Hall Tweak
  11. ; - Changed to MASM format.
  12. ; - Added full baud table for superhi rates
  13. ;   (Requires second cmdline parm).
  14. ; - Added some usage/error msgs.
  15. ;
  16. ;David Kirschbaum
  17. ;Toad Hall
  18.  
  19. _19200    equ    6        ;19200 bps divisor
  20. _38400    equ    3        ;38400 baud
  21. _57600    equ    2        ;57600 baud
  22. _115200    equ    1        ;donno if this'll work
  23.  
  24. ;DIVISOR equ    _38400        ;whatever
  25.  
  26. CR    equ    0DH
  27. LF    equ    0AH
  28.  
  29. CSEG    segment para public 'CODE'
  30.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG
  31.  
  32.     org    100H
  33.  
  34. Baud    proc    near
  35.  
  36.     CLD
  37.     mov    dx,offset usage        ;help msg
  38.     xor    ah,ah            ;clear msb
  39.     MOV    SI,81H            ;point to command line buffer
  40.  
  41. PortLup:
  42.     LODSB                ;get byte
  43.     CMP    AL,0DH            ;carriage return?
  44.     JZ    MsgExit            ;yes, display usage, exit
  45.     CMP    AL,31H            ;is it less than a "1"?
  46.     JB    PortLup            ;yes, loop
  47.     CMP    AL,34H            ;is it more than a "4"?
  48.     JA    PortLup            ;yes, loop
  49.  
  50.     SUB    AL,31H            ;correct to binary (COM1=0, COM2=1,
  51.                     ; COM3=2, COM4=3)
  52.  
  53. ;    ROL    AX,1            ;multiply by two to later point
  54.     shl    ax,1            ;*2 for 16-bit offset
  55.     MOV    BX,AX            ;save port offset in BX for later use
  56.  
  57. ;v1.1 2d parm could be "1", "3", "5", '+' (for 19200, 38400, 57600 bps)
  58. ; or '+' for superhi (unlikely)
  59.  
  60. BaudLup:
  61.     lodsb                ;get byte
  62.     cmp    al,CR            ;carriage return?
  63.     jz    MsgExit            ;yes, display usage, exit
  64.     cmp    al,' '            ;just a spacer?
  65.     jz    BaudLup            ;yep, gobble it
  66.     cmp    al,'1'            ;'19200'?
  67.     jz    GotBaud            ;yep
  68.     cmp    al,'3'            ;'38400'?
  69.     jz    GotBaud            ;yep
  70.     cmp    al,'5'            ;'57600'?
  71.     jz    GotBaud
  72.     cmp    al,'+'            ;superhi?
  73.     mov    al,'7'            ;assume yes
  74.     jnz    MsgExit            ;nope, error, show usage
  75.     
  76. GotBaud:
  77.     sub    AL,31H            ;correct to binary and table offset
  78.                     ; ('1' = 0, '3' = 2,'5' = 4, etc.)
  79.     add    ax,offset baudtbl    ;baud table base
  80.     mov    si,ax            ;SI -> baud table[baud] (words)
  81.  
  82.     XOR    AX,AX            ;zero A register pair
  83.     mov    DS,ax            ;put it in the segment register
  84.     ASSUME    DS:NOTHING
  85.  
  86.     mov    ax,offset noport    ;possible error msg
  87.     MOV    DX,[BX+400H]        ;get 16-bit port base address
  88.     TEST    DX,DX            ;check to see if there's a port defined
  89.     xchg    ax,dx            ;assume failure (err msg in DX)
  90.     jz    MsgExit            ;yep, error msg, exit
  91.  
  92.     xchg    ax,dx            ;swap port addr back to DX
  93.  
  94.     mov    cx,3            ;get a handy constant
  95.     add    dx,cx            ;index to uart line control register
  96.     IN    AL,DX            ;get current status byte (like 8N1)
  97.  
  98.     MOV    BL,AL            ;save current status byte in BL
  99.     OR    AL,80H            ;set bit 7 to tell uart we're setting
  100.                     ; divisor rate
  101.     OUT    DX,AL            ;tell uart
  102.  
  103.     sub    dx,cx            ;index to divisor latch
  104. ;    mov    ax,DIVISOR        ;the baudrate divisor you want
  105.     mov    ax,CS:[si]        ;snarf correct baud rate divisor word
  106.     OUT    DX,AX            ;set new rate
  107.  
  108.     add    dx,cx            ;index back to uart
  109.                     ; line control register
  110.     MOV    AL,BL            ;get saved status
  111.     OUT    DX,AL            ;restore old status
  112.     mov    dx,offset beep        ;just beep to ack it happened
  113.  
  114. MsgExit:
  115.     mov    ax,CS            ;insure DS=CS
  116.     mov    DS,ax
  117.     mov    ah,9            ;display msg in DX
  118.     int    21H
  119.  
  120.     INT    20H            ;terminate
  121.  
  122. baudtbl    dw    _19200            ;'1'
  123.     dw    _38400            ;'3'
  124.     dw    _57600            ;'5'
  125.     dw    _115200            ;'+'
  126.  
  127. usage    label    byte
  128.  db 'TOADMODE.COM will increase the baud rate of COM ports 1-4',CR,LF
  129.  db 'to rates higher than the DOS MODE command permits.',CR,LF
  130.  db 'TOADMODE.COM must be used after the MODE command!',CR,LF,LF
  131.  db 'Syntax for configuration:',CR,LF,LF
  132.  db 'C:\>mode COMx:9600,n,8,1',CR,LF
  133.  db 'C:\>toadmode x b',CR,LF,LF
  134.  db '    where x = 1 for COM1',CR,LF
  135.  db '          2 for COM2',CR,LF
  136.  db '          3 for COM3',CR,LF
  137.  db '          4 for COM4',CR,LF
  138.  db '    and   b = 1 for 19200 bps',CR,LF
  139.  db '          3 for 38400 bps',CR,LF
  140.  db '          5 for 57600 bps',CR,LF
  141.  db '          + for 115,200 bps',CR,LF,LF
  142.  db '(No guarantees your serial card UART will run at ANY of these speeds!)'
  143.  db CR,LF,'v1.1, Courtesy of David Kirschbaum, Toad Hall',CR,LF,'$'
  144.  
  145. noport    db    7,'No COM port found',CR,LF,'$'
  146.  
  147. beep    db    7,'$'
  148.  
  149. Baud    endp
  150.  
  151. CSEG    ENDS
  152.     END    Baud
  153.